#coding: utf-8


class Solution:
    # 寻找最长回文串
    def longestPalindrome(self, s: str) -> str:
        cur = 0
        # 太短则直接不需要判断了
        if len(s) <= 1:
            return s

        cur = 0
        cur_left = cur_right = 0
        for i in range(1, len(s)):
            left = right = 0
            for j in range(2):
                # 中间是一个数的一定执行
                if j == 0:
                    left = i-1
                    right = i+1
                # 第二次，若中间是俩的再来一次
                elif j == 1 and s[i] == s[i-1]:
                    left = i-2
                    right = i+1
                while left >= 0 and right < len(s) and s[left] == s[right]:
                    left = left-1
                    right = right + 1
                right = right - 1
                left = left + 1
                if right - left > cur:
                    cur = right-left
                    cur_left = left
                    cur_right = right

        return s[cur_left:cur_right+1]


if __name__ == "__main__":
    solu = Solution()
    print(solu.longestPalindrome('ccc'))
